/**
 *@NApiVersion 2.x
 *@NScriptType UserEventScript
 */
define(['N/record', 'N/render', 'N/task'], function (record, render, task) {
    function beforeLoad(context) {
        if (context.type === 'view') {
            try {
                var id = context.newRecord.id;
                var url = "/app/site/hosting/scriptlet.nl?script=163&deploy=1" + "&recid=" + id;
                var form = context.form;
                form.addButton({
                    id: 'custpage_button',
                    label: '更新制造费',
                    functionName: "window.open('" + url + "');"
                });

                form.addButton({
                    id: 'custpage_button',
                    label: '取消启用更新',
                    functionName: cancel(id)
                });


            } catch (e) {
                log.error(e.name, e.message);
            }

        }
    }

    function cancel(id) {
        record.submitFields({
            type: 'customrecord_monthmanufactureexpense',
            id: id,
            values: {
                custrecord_enable_update: false
            }
        });
    }
    return {
        beforeLoad: beforeLoad
    };
});
